package com.ruoyi.project.infoprojecttargetindex.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.infoprojecttargetindex.domain.InfoProjectTargetIndex;
import com.ruoyi.project.infoprojecttargetindex.mapper.InfoProjectTargetIndexMapper;
import com.ruoyi.project.infoprojecttargetindex.service.IInfoProjectTargetIndexService;
import com.ruoyi.project.infoprojecttargetindex.vo.InfoProjectTargetIndexVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;


/**
 * 项目目标填报—中的指标Service业务层处理
 *
 * @author ruoyi
 * @date 2022-02-08
 */
@Service
public class InfoProjectTargetIndexServiceImpl implements IInfoProjectTargetIndexService {
    @Autowired
    private InfoProjectTargetIndexMapper infoProjectTargetIndexMapper;

    /**
     * 查询项目目标填报—中的指标
     *
     * @param id 项目目标填报—中的指标主键
     * @return 项目目标填报—中的指标
     */
    @Override
    public InfoProjectTargetIndex selectInfoProjectTargetIndexById(Long id) {
        return infoProjectTargetIndexMapper.selectInfoProjectTargetIndexById(id);
    }

    /**
     * 查询项目目标填报—中的指标列表
     *
     * @param infoProjectTargetIndex 项目目标填报—中的指标
     * @return 项目目标填报—中的指标
     */
    @Override
    public List<InfoProjectTargetIndex> selectInfoProjectTargetIndexList(InfoProjectTargetIndex infoProjectTargetIndex) {
        return infoProjectTargetIndexMapper.selectInfoProjectTargetIndexList(infoProjectTargetIndex);
    }

    /**
     * 新增项目目标填报—中的指标
     *
     * @param infoProjectTargetIndex 项目目标填报—中的指标
     * @return 结果
     */
    @Override
    public int insertInfoProjectTargetIndex(InfoProjectTargetIndex infoProjectTargetIndex) {
        infoProjectTargetIndex.setCreateTime(DateUtils.getNowDate());
        return infoProjectTargetIndexMapper.insertInfoProjectTargetIndex(infoProjectTargetIndex);
    }

    /**
     * 修改项目目标填报—中的指标
     *
     * @param infoProjectTargetIndex 项目目标填报—中的指标
     * @return 结果
     */
    @Override
    public int updateInfoProjectTargetIndex(InfoProjectTargetIndex infoProjectTargetIndex) {
        infoProjectTargetIndex.setUpdateTime(DateUtils.getNowDate());
        return infoProjectTargetIndexMapper.updateInfoProjectTargetIndex(infoProjectTargetIndex);
    }

    /**
     * 批量删除项目目标填报—中的指标
     *
     * @param ids 需要删除的项目目标填报—中的指标主键
     * @return 结果
     */
    @Override
    public int deleteInfoProjectTargetIndexByIds(Long[] ids) {
        return infoProjectTargetIndexMapper.deleteInfoProjectTargetIndexByIds(ids);
    }

    /**
     * 删除项目目标填报—中的指标信息
     *
     * @param id 项目目标填报—中的指标主键
     * @return 结果
     */
    @Override
    public int deleteInfoProjectTargetIndexById(Long id) {
        return infoProjectTargetIndexMapper.deleteInfoProjectTargetIndexById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int batchInsertProjectTargetIndex(InfoProjectTargetIndexVo projectIndexVo) {
        try {
            List<InfoProjectTargetIndex> projectIndexList = projectIndexVo.getProjectIndexList();
            for (InfoProjectTargetIndex infoProjectTargetIndex : projectIndexList) {
                infoProjectTargetIndex.setId(null);
                infoProjectTargetIndex.setProjectId(projectIndexVo.getProjectId());
                infoProjectTargetIndexMapper.insertInfoProjectTargetIndex(infoProjectTargetIndex);
            }
            return 1;
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return 0;
        }
    }
}
